//
//  DLGesPswButton.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/12/28.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLGesPswButton.h"
#import "DLGesPswBgView.h"
#import "DLGesPswManager.h"

@implementation DLGesPswButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = NO;
    }
    return self;
}

- (void) drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    DLGesPswBgView *gesBgView = nil;
    if ([self.superview isKindOfClass:[DLGesPswBgView class]]) {
        gesBgView = (DLGesPswBgView *)self.superview;
    }
    [gesBgView.strokeColor setStroke];
    
    
    DLGesPswManager *manager = [DLGesPswManager sharedInstance];
    
    CGFloat radius = manager.circleRadius - manager.strokeWidth;
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, manager.strokeWidth);
    
    CGPoint centerPoint = CGPointMake(rect.size.width, rect.size.height);
    CGFloat startAngle = -((CGFloat)M_PI/2);
    CGFloat endAngle = ((2 * (CGFloat)M_PI) + startAngle);
    
    CGContextAddArc(context, centerPoint.x, centerPoint.y, radius, startAngle, endAngle, 0);
    CGContextStrokePath(context);
    
    if (manager.showCenterPoint) {
        //同时设置填充和边框色
        [gesBgView.fillColor set];
        CGContextAddArc(context, centerPoint.x, centerPoint.y, radius, startAngle, endAngle, 0);
        CGContextFillPath(context);
        if (manager.fillCenterPoint) {
            [gesBgView.centerPointColor set];//同时设置填充和边框色
        }else{
            [gesBgView.centerPointColor setStroke];//设置边框色
        }
        CGContextAddArc(context, centerPoint.x, centerPoint.y, manager.centerPointRadius, startAngle, endAngle, 0);
        if (manager.fillCenterPoint) {
            CGContextFillPath(context);
        }else{
            CGContextStrokePath(context);
        }
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
